<?php
/**
 * Dcolors,The Community Application for Web
 *
 * Init class
 *
 * Not free software
 * @author     chopin xiao <x@sunsne.com>
 * @copyright  2009 The Dcolors Group
 * @version    SVN: $Id: init.php 15 2009-01-19 11:36:08Z chopins.xiao $
 **/

define('APP',dirname(__FILE__));
require_once(APP.'/configure.php');
abstract class Init extends Globals 
{
	public $configure;
	public $db;
	public $params;
	protected $sid = null;
	public function __construct()
	{
		$this->extra($_GET);
		$this->extra($_POST);
		$this->extra($_COOKIE);
		$this->configure = $GLOBALS['config'];
		$this->db = new mysql($this->configure['dbhost'],$this->configure['dbname'],$this->configure['dbuser'],$this->configure['dbpass']);
		$this->session();
		$this->action();
	}
	public function extra(&$array)
	{
		if(is_array($array)){
			foreach ($array as $k => $v){
				$this->params[$k] = $v;
			}
		}
	}
	public function action()
	{
		if(empty($this->params['action']))
			return false;
		$action = $this->params['action'];
		return $this->$action();
	}
	public function session()
	{
		session_start();
		$_SESSION['vid'] = md5($this->randstr(10,5).$this->getvistip().$this->getdate('sec'));
		if(!empty($_SESSION['login']) && $_SESSION['login'] == true)
			$this->sid = $_SESSION['vid'];
	}
}
function __autoload($class_name)
{
	return include_once(APP."/Lib/{$class_name}.php");
}
